package com.ruleengine.worker.model;

import java.util.Map;

import com.ruleengine.util.model.Metadata;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * @author lianghanwei on 2024/3/3
 */
@ToString
@Builder(toBuilder = true)
@Getter
public class Rule {

    @Builder.Default
    private String apiVersion = "v1";

    @Builder.Default
    private ResourceKind kind = ResourceKind.RULE;

    private Metadata metadata;

    private Spec spec;

    @Setter
    private Status status;

    private String rulechainId;

    private int rulechainVersion;

    @ToString
    @Builder(toBuilder = true)
    @Getter
    public static class Spec {

        private RuleType type;

        private Map<String, String> args;

    }

    public enum RuleType {
        /**
         * only for test
         */
        SIMPLE_LOG,

        /**
         * only for chain runner
         */
        DISPATCH,

        JSON_FILTER,

        JSON_MAP,

        DEST_BIFROMQ,

        DEST_KAFKA;

        public static boolean isDestinationType(RuleType type) {
            if (type.ordinal() >= 4) {
                return true;
            }
            return false;
        }
    }
}
